package com.example.travel.service;

import com.example.travel.mapper.CategoryMapper;
import com.example.travel.mapper.RouteImgMapper;
import com.example.travel.mapper.RouteMapper;
import com.example.travel.mapper.SellerMapper;
import com.example.travel.pojo.Category;
import com.example.travel.pojo.Route;
import com.example.travel.pojo.RouteImg;
import com.example.travel.pojo.Seller;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RouteService {

    @Autowired
    private RouteMapper routeMapper;

    @Autowired
    private CategoryMapper categoryMapper;

    @Autowired
    private SellerMapper sellerMapper;


    //查询所有分类
    public List<Category> allCategory(){

        return categoryMapper.selectList(null);
    }

    //查询所有旅游公司
    public List<Seller> allSeller(){

        return sellerMapper.selectList(null);
    }

    //多条件分页查询
    public PageInfo<Route> PageInfoFindByParam(Integer pageNum,Integer pageSize,Route route){

        return PageHelper.startPage(pageNum,pageSize).doSelectPageInfo(()->{
            routeMapper.findByParam(route);
        });
    }

    //添加线路数据
    public int addRoute(Route route){

        return routeMapper.insert(route);
    }

    //主键查询数据
    public Route getInfoById(Integer rid){

        return routeMapper.selectById(rid);
    }

    //更新数据
    public int updateRoute(Route route){

        return routeMapper.updateById(route);
    }

    //删除数据
    public int deleteRoute(Integer rid){

        return routeMapper.deleteById(rid);
    }

}
